﻿using System;
using System.Windows.Forms;
using FileDuplicateRemover.Core;
using Useful.GUI;

namespace FileDuplicateRemover.Gui
{
    public class GridItem
    {
        private BaseEntity _Entity;
        private DuplicateEntityDescription _DuplicateEntityDescription;

        [ExDisplayName("ID", 10)]
        public string ID
        {
            get
            {
                return _DuplicateEntityDescription.ID;
            }
        }

        [ExDisplayName("Имя", 20)]
        public string Name
        {
            get
            {
                return _Entity.FullName;
            }
        }

        [ExDisplayName("Кол-во", 30)]
        public int Count
        {
            get
            {
                return _DuplicateEntityDescription.DuplicateCount;
            }
        }

        [ExDisplayName("Размер", 40, DataGridViewAutoSizeColumnMode.AllCells, "N0", true)]
        public long Length
        {
            get
            {
                return _Entity.TotalLength;
            }
        }

        private string _Length2 = null;

        [ExDisplayName("Размер 2", 40, DataGridViewAutoSizeColumnMode.AllCells, "N0", true)]
        public string Length2
        {
            get
            {
                if (_Length2 == null)
                {
                    double b = _Entity.TotalLength;

                    double kb = b/1024;
                    double mb = kb/1024;
                    double gb = mb/1024;

                    if (Math.Floor(gb) != 0)
                        _Length2 = String.Format("{0:N2} Гб", gb);
                    else if (Math.Floor(mb) != 0)
                        _Length2 = String.Format("{0:N2} Мб", mb);
                    else if (Math.Floor(kb) != 0)
                        _Length2 = String.Format("{0:N2} Кб", kb);
                    else
                        _Length2 = String.Format("{0:N2} б", b);
                }

                return _Length2;
            }
        }

        public GridItem(DuplicateEntityDescription ded, BaseEntity e, bool isFirst)
        {
            _DuplicateEntityDescription = ded;
            _Entity = e;
            IsFirst = isFirst;
        }

        //public GridItem() : this(null, null, false))
        //{
            
        //}

        public override string ToString()
        {
            return String.Format("{0} [{1}]", Name, Length);
        }

        [ExDisplayName("", 5)]
        public bool Checked { get; set; }

        public bool IsFirst { get; set; }
        public bool IsDeleted { get; set; }

        public bool IsDirectory
        {
            get
            {
                return _Entity is DirectoryEntity;
            }
        }

        public BaseEntity Entity
        {
            get
            {
                return _Entity;
            }
        }

        [ExDisplayName("Результат", 100)]
        public string Result { get; set; }

        public DateTime Created
        {
            get
            {
                return _Entity.Created;
            }
        }
    }
}
